|
1
|
|
|
var g_chosen_datetimes = []; |
|
2
|
|
|
var g_chosen_texts = []; |
|
3
|
|
|
var g_chosen_groups = []; |
|
4
|
|
|
var g_chosen_users = []; |
|
5
|
|
|
var chosen_type = 'event'; |
|
6
|
|
|
var access_type = ''; |
|
7
|
|
|
var isAnonymous; |
|
8
|
|
|
var hideNames; |
|
9
|
|
|
|
|
10
|
|
|
function selectItem(cell) { |
|
11
|
|
|
cell.removeClass('icon-close'); |
|
12
|
|
|
cell.addClass('icon-checkmark'); |
|
13
|
|
|
cell.removeClass('date-text-not-selected'); |
|
14
|
|
|
cell.addClass('date-text-selected'); |
|
15
|
|
|
if (cell.attr('class').indexOf('is-text') > -1) { |
|
16
|
|
|
var id = cell.attr('id'); |
|
17
|
|
|
g_chosen_texts.push(id.substring(id.indexOf('_') + 1)); |
|
18
|
|
|
} else { |
|
19
|
|
|
var dateId = cell.parent().attr('id'); //timestamp of date |
|
20
|
|
|
var timeId = cell.attr('id'); |
|
21
|
|
|
g_chosen_datetimes.push(parseInt(dateId) + parseInt(timeId)); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
function deselectItem(cell) { |
|
26
|
|
|
var id; |
|
27
|
|
|
var index; |
|
28
|
|
|
var dateId; |
|
29
|
|
|
var timeId; |
|
30
|
|
|
cell.removeClass('icon-checkmark'); |
|
31
|
|
|
cell.addClass('icon-close'); |
|
32
|
|
|
cell.removeClass('date-text-selected'); |
|
33
|
|
|
cell.addClass('date-text-not-selected'); |
|
34
|
|
|
if (cell.attr('class').indexOf('is-text') > -1) { |
|
35
|
|
|
id = cell.attr('id'); |
|
36
|
|
|
index = g_chosen_texts.indexOf(id.substring(id.indexOf('_') + 1)); |
|
37
|
|
|
if (index > -1) { |
|
38
|
|
|
g_chosen_texts.splice(index, 1); |
|
39
|
|
|
} |
|
40
|
|
|
} else { |
|
41
|
|
|
dateId = cell.parent().attr('id'); //timestamp of date |
|
42
|
|
|
timeId = cell.attr('id'); |
|
43
|
|
|
index = g_chosen_datetimes.indexOf(parseInt(dateId) + parseInt(timeId)); |
|
44
|
|
|
if (index > -1) { |
|
45
|
|
|
g_chosen_datetimes.splice(index, 1); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function insertText(text, set) { |
|
51
|
|
|
if (typeof set === 'undefined') { |
|
52
|
|
|
set = false; |
|
53
|
|
|
} |
|
54
|
|
|
var table = document.getElementById('selected-texts-table'); |
|
55
|
|
|
var tr = table.insertRow(-1); |
|
56
|
|
|
var td = tr.insertCell(-1); |
|
57
|
|
|
td.innerHTML = text; |
|
58
|
|
|
td.className = 'text-row'; |
|
59
|
|
|
td = tr.insertCell(-1); |
|
60
|
|
|
if (set) { |
|
61
|
|
|
td.className = 'icon-checkmark is-text date-text-selected'; |
|
62
|
|
|
} else { |
|
63
|
|
|
td.className = 'icon-close is-text date-text-not-selected'; |
|
64
|
|
|
} |
|
65
|
|
|
td.id = 'text_' + text; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function addRowToList(ts, text, timeTs) { |
|
69
|
|
|
if (typeof timeTs === 'undefined') { |
|
70
|
|
|
timeTs = -1; |
|
71
|
|
|
} |
|
72
|
|
|
var table = document.getElementById('selected-dates-table'); |
|
73
|
|
|
var rows = table.rows; |
|
74
|
|
|
var td, tr, tdId; |
|
75
|
|
|
var i, j; |
|
76
|
|
|
var curr; |
|
77
|
|
|
if (rows.length === 0) { |
|
78
|
|
|
tr = table.insertRow(-1); //start new header |
|
79
|
|
|
tr.insertCell(-1); |
|
80
|
|
|
tr = table.insertRow(-1); //append new row |
|
81
|
|
|
tr.id = ts; |
|
82
|
|
|
tr.className = 'toggleable-row'; |
|
83
|
|
|
td = tr.insertCell(-1); |
|
84
|
|
|
td.className = 'date-row'; |
|
85
|
|
|
td.innerHTML = text; |
|
86
|
|
|
return; |
|
87
|
|
|
} |
|
88
|
|
|
for ( i=1; i<rows.length; i++) { |
|
89
|
|
|
curr = rows[i]; |
|
90
|
|
|
if (curr.id === ts) { |
|
91
|
|
|
for (j=1; j<curr.cells.length; j++) { |
|
92
|
|
|
td = curr.cells[j]; |
|
93
|
|
|
tdId = curr.cells[j].id; |
|
94
|
|
|
if ( timeTs === tdId) { |
|
95
|
|
|
td.className = 'icon-checkmark date-text-selected'; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
return; //already in table, cancel |
|
99
|
|
|
} else if (curr.id > ts) { |
|
100
|
|
|
tr = table.insertRow(i); //insert row at current index |
|
101
|
|
|
tr.id = ts; |
|
102
|
|
|
tr.className = 'toggleable-row'; |
|
103
|
|
|
td = tr.insertCell(-1); |
|
104
|
|
|
td.className = 'date-row'; |
|
105
|
|
|
td.innerHTML = text; |
|
106
|
|
|
for (j=1; j<rows[0].cells.length; j++) { |
|
107
|
|
|
tdId = rows[0].cells[j].id; |
|
108
|
|
|
td = tr.insertCell(-1); |
|
109
|
|
|
if (timeTs === tdId) { |
|
110
|
|
|
td.className = 'icon-checkmark date-text-selected'; |
|
111
|
|
|
} else { |
|
112
|
|
|
td.className = 'icon-close date-text-not-selected'; |
|
113
|
|
|
} |
|
114
|
|
|
td.id = tdId; |
|
115
|
|
|
td.innerHTML = ''; |
|
116
|
|
|
} |
|
117
|
|
|
return; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
tr = table.insertRow(-1); //highest value, append new row |
|
121
|
|
|
tr.id = ts; |
|
122
|
|
|
tr.className = 'toggleable-row'; |
|
123
|
|
|
td = tr.insertCell(-1); |
|
124
|
|
|
td.className = 'date-row'; |
|
125
|
|
|
td.innerHTML = text; |
|
126
|
|
|
for (j=1; j<rows[0].cells.length; j++) { |
|
127
|
|
|
tdId = rows[0].cells[j].id; |
|
128
|
|
|
td = tr.insertCell(-1); |
|
129
|
|
|
if (timeTs === tdId) { |
|
130
|
|
|
td.className = 'icon-checkmark date-text-selected'; |
|
131
|
|
|
} else { |
|
132
|
|
|
td.className = 'icon-close date-text-not-selected'; |
|
133
|
|
|
} |
|
134
|
|
|
td.id = tdId; |
|
135
|
|
|
td.innerHTML = ''; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
function addColToList(ts, text, dateTs) { |
|
140
|
|
|
if (typeof dateTs === 'undefined') { |
|
141
|
|
|
dateTs = -1; |
|
142
|
|
|
} |
|
143
|
|
|
var table = document.getElementById('selected-dates-table'); |
|
144
|
|
|
var rows = table.rows; |
|
145
|
|
|
var tr, row, td, cells, tmpRow; |
|
146
|
|
|
var i, curr; |
|
147
|
|
|
var index = -1; |
|
148
|
|
|
if (rows.length === 0) { |
|
149
|
|
|
tr = table.insertRow(-1); |
|
150
|
|
|
tr.insertCell(-1); |
|
151
|
|
|
} |
|
152
|
|
|
rows = table.rows; |
|
153
|
|
|
tmpRow = rows[0]; |
|
154
|
|
|
for (i=0; i<tmpRow.cells.length; i++) { |
|
155
|
|
|
curr = tmpRow.cells[i]; |
|
156
|
|
|
if (curr.id === ts) { |
|
157
|
|
|
return; //already in table, cancel |
|
158
|
|
|
} else if (curr.id > ts) { |
|
159
|
|
|
index = i; |
|
160
|
|
|
break; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
for (i=0; i<rows.length; i++) { |
|
165
|
|
|
row = rows[i]; |
|
166
|
|
|
cells = row.cells; |
|
167
|
|
|
td = row.insertCell(index); |
|
168
|
|
|
//only display time in header row |
|
169
|
|
|
if (i===0) { |
|
170
|
|
|
td.innerHTML = text; |
|
171
|
|
|
td.className = 'date-col'; |
|
172
|
|
|
} else { |
|
173
|
|
|
td.innerHTML = ''; |
|
174
|
|
|
if (row.id === dateTs) { |
|
175
|
|
|
td.className = 'icon-checkmark date-text-selected'; |
|
176
|
|
|
} else { |
|
177
|
|
|
td.className = 'icon-close date-text-not-selected'; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
td.id = ts; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
function debounce(f, wait, immediate) { |
|
185
|
|
|
var timeout; |
|
186
|
|
|
return function() { |
|
187
|
|
|
var context = this; |
|
188
|
|
|
var args = arguments; |
|
189
|
|
|
var later = function() { |
|
190
|
|
|
timeout = null; |
|
191
|
|
|
if (!immediate) { |
|
192
|
|
|
f.apply(context, args); |
|
193
|
|
|
} |
|
194
|
|
|
}; |
|
195
|
|
|
var callNow = immediate && !timeout; |
|
196
|
|
|
clearTimeout(timeout); |
|
|
|
|
|
|
197
|
|
|
timeout = setTimeout(later, wait); |
|
198
|
|
|
if (callNow) { |
|
199
|
|
|
f.apply(context, args); |
|
200
|
|
|
} |
|
201
|
|
|
}; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$(document).ready(function () { |
|
205
|
|
|
// enable / disable date picker |
|
206
|
|
|
var i; |
|
207
|
|
|
$('#id_expire_set').click(function(){ |
|
208
|
|
|
$('#id_expire_date').prop("disabled", !this.checked); |
|
209
|
|
|
if (this.checked) { |
|
210
|
|
|
$("#id_expire_date").focus(); |
|
211
|
|
|
} |
|
212
|
|
|
}); |
|
213
|
|
|
|
|
214
|
|
|
var anonOptions = document.getElementById('anonOptions'); |
|
215
|
|
|
$('#hideNames').click(function() { |
|
216
|
|
|
hideNames = this.checked; |
|
217
|
|
|
}); |
|
218
|
|
|
|
|
219
|
|
|
$('#isAnonymous').click(function() { |
|
220
|
|
|
isAnonymous = this.checked; |
|
221
|
|
|
if (isAnonymous) { |
|
222
|
|
|
anonOptions.style.display = 'inline'; |
|
223
|
|
|
} else { |
|
224
|
|
|
anonOptions.style.display = 'none'; |
|
225
|
|
|
} |
|
226
|
|
|
}); |
|
227
|
|
|
|
|
228
|
|
|
var privateRadio = document.getElementById('private'); |
|
229
|
|
|
var hiddenRadio = document.getElementById('hidden'); |
|
230
|
|
|
var publicRadio = document.getElementById('public'); |
|
231
|
|
|
var selectRadio = document.getElementById('select'); |
|
232
|
|
|
if (privateRadio.checked) { |
|
233
|
|
|
access_type = 'registered'; |
|
234
|
|
|
} else if (hiddenRadio.checked) { |
|
235
|
|
|
access_type = 'hidden'; |
|
236
|
|
|
} else if (publicRadio.checked) { |
|
237
|
|
|
access_type = 'public'; |
|
238
|
|
|
} else if (selectRadio.checked) { |
|
239
|
|
|
access_type = 'select'; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
isAnonymous = document.getElementById('isAnonymous').checked; |
|
243
|
|
|
hideNames = anonOptions.checked; |
|
244
|
|
|
|
|
245
|
|
|
var accessValues = document.getElementById('accessValues'); |
|
246
|
|
|
if (accessValues.value.length > 0) { |
|
247
|
|
|
var list = document.getElementById('selected-search-list-id'); |
|
248
|
|
|
var accessValueArr = accessValues.value.split(';'); |
|
249
|
|
|
for (i=0; i<accessValueArr.length; i++) { |
|
250
|
|
|
var val = accessValueArr[i]; |
|
251
|
|
|
if (val === '') { |
|
252
|
|
|
continue; |
|
253
|
|
|
} |
|
254
|
|
|
var li = document.createElement('li'); |
|
255
|
|
|
li.id = val; |
|
256
|
|
|
li.className = 'cl_item cl_access_item selected'; |
|
257
|
|
|
var index = val.indexOf('group_'); |
|
258
|
|
|
if (index === 0) { |
|
259
|
|
|
g_chosen_groups.push(val); |
|
260
|
|
|
li.className += ' is-group'; |
|
261
|
|
|
li.appendChild(document.createTextNode(val.substring(6) + " (group)")); |
|
262
|
|
|
list.appendChild(li); |
|
263
|
|
|
} else { |
|
264
|
|
|
index = val.indexOf('user_'); |
|
265
|
|
|
if (index === 0) { |
|
266
|
|
|
g_chosen_users.push(val); |
|
267
|
|
|
li.className = 'cl_item cl_access_item selected'; |
|
268
|
|
|
var username = val.substring(5); |
|
269
|
|
|
$.post(OC.generateUrl('/apps/polls/get/displayname'), {username: username}, function(data) { |
|
|
|
|
|
|
270
|
|
|
li.appendChild(document.createTextNode(username + " (" + data + ")")); |
|
|
|
|
|
|
271
|
|
|
list.appendChild(li); |
|
272
|
|
|
}); |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
var chosenDates = document.getElementById('chosenDates').value; |
|
279
|
|
|
var chosen = ''; |
|
280
|
|
|
if (chosenDates.length > 0) { |
|
281
|
|
|
chosen = JSON.parse(chosenDates); |
|
282
|
|
|
} |
|
283
|
|
|
var text = document.getElementById('text'); |
|
284
|
|
|
var event = document.getElementById('event'); |
|
285
|
|
|
if (event.checked) { |
|
286
|
|
|
chosen_type = event.value; |
|
287
|
|
|
if (chosenDates.length > 0) { |
|
288
|
|
|
g_chosen_datetimes = chosen; |
|
289
|
|
|
} |
|
290
|
|
|
for (i=0; i<chosen.length; i++) { |
|
291
|
|
|
var date = new Date(chosen[i]*1000); |
|
292
|
|
|
var year = date.getFullYear(); |
|
293
|
|
|
var month = date.getMonth(); |
|
294
|
|
|
var day = date.getDate(); |
|
295
|
|
|
var newDate = new Date(year, month, day).getTime(); //save timestamp without time of day |
|
296
|
|
|
month = '0' + (month+1); //month is 0-11, so +1 |
|
297
|
|
|
day = '0' + day; |
|
298
|
|
|
var dateStr = day.substr(-2) + '.' + month.substr(-2) + '.' + year; |
|
299
|
|
|
var hours = date.getHours(); |
|
300
|
|
|
var minutes = date.getMinutes(); |
|
301
|
|
|
var ms = (hours * 60 * 60 * 1000) + (minutes * 60 * 1000); //time of day in milliseconds |
|
302
|
|
|
hours = '0' + hours; |
|
303
|
|
|
minutes = '0' + minutes; |
|
304
|
|
|
var timeStr = hours.substr(-2) + ':' + minutes.substr(-2); |
|
305
|
|
|
addRowToList(newDate/1000, dateStr, ms/1000); |
|
306
|
|
|
addColToList(ms/1000, timeStr, newDate/1000); |
|
307
|
|
|
} |
|
308
|
|
|
} else { |
|
309
|
|
|
chosen_type = text.value; |
|
310
|
|
|
if (chosenDates.length > 0) { |
|
311
|
|
|
g_chosen_texts = chosen; |
|
312
|
|
|
} |
|
313
|
|
|
for (i=0; i<chosen.length; i++) { |
|
314
|
|
|
insertText(chosen[i], true); |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
var expirepicker = jQuery('#id_expire_date').datetimepicker({ |
|
|
|
|
|
|
319
|
|
|
inline: false, |
|
320
|
|
|
onSelectDate: function(date) { |
|
321
|
|
|
var year = date.getFullYear(); |
|
322
|
|
|
var month = date.getMonth(); |
|
323
|
|
|
var day = date.getDate(); |
|
324
|
|
|
var newDate = new Date(year, month, day).getTime()/1000; |
|
325
|
|
|
document.getElementById('expireTs').value = newDate; |
|
326
|
|
|
}, |
|
327
|
|
|
timepicker: false, |
|
328
|
|
|
format: 'd.m.Y' |
|
329
|
|
|
}); |
|
330
|
|
|
|
|
331
|
|
|
var datepicker = jQuery('#datetimepicker').datetimepicker({ |
|
|
|
|
|
|
332
|
|
|
inline:true, |
|
333
|
|
|
step: 15, |
|
334
|
|
|
todayButton: true, |
|
335
|
|
|
onSelectDate: function(date) { |
|
336
|
|
|
var year = date.getFullYear(); |
|
337
|
|
|
var month = date.getMonth(); |
|
338
|
|
|
var day = date.getDate(); |
|
339
|
|
|
var newDate = new Date(year, month, day).getTime(); //save timestamp without time of day |
|
340
|
|
|
month = '0' + (month+1); //month is 0-11, so +1 |
|
341
|
|
|
day = '0' + day; |
|
342
|
|
|
var dateStr = day.substr(-2) + '.' + month.substr(-2) + '.' + year; |
|
343
|
|
|
addRowToList(newDate/1000, dateStr); |
|
344
|
|
|
}, |
|
345
|
|
|
onSelectTime: function(date) { |
|
346
|
|
|
var hours = date.getHours(); |
|
347
|
|
|
var minutes = date.getMinutes(); |
|
348
|
|
|
var ms = (hours * 60 * 60 * 1000) + (minutes * 60 * 1000); //time of day in milliseconds |
|
349
|
|
|
hours = '0' + hours; |
|
350
|
|
|
minutes = '0' + minutes; |
|
351
|
|
|
var timeStr = hours.substr(-2) + ':' + minutes.substr(-2); |
|
352
|
|
|
addColToList(ms/1000, timeStr); |
|
353
|
|
|
} |
|
354
|
|
|
}); |
|
355
|
|
|
|
|
356
|
|
|
$(document).on('click', '.date-row', function() { |
|
357
|
|
|
var tr = $(this).parent(); |
|
358
|
|
|
var dateId = parseInt(tr.attr('id')); |
|
359
|
|
|
var index = tr.index(); |
|
360
|
|
|
var cells = tr[0].cells; //convert jQuery object to DOM |
|
361
|
|
|
for (var i=1; i<cells.length; i++) { |
|
362
|
|
|
var cell = cells[i]; |
|
363
|
|
|
var delIndex = g_chosen_datetimes.indexOf(dateId + parseInt(cell.id)); |
|
364
|
|
|
if (delIndex > -1) { |
|
365
|
|
|
g_chosen_datetimes.splice(delIndex, 1); |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
var table = document.getElementById('selected-dates-table'); |
|
369
|
|
|
table.deleteRow(index); |
|
370
|
|
|
}); |
|
371
|
|
|
|
|
372
|
|
|
$(document).on('click', '.date-col', function() { |
|
373
|
|
|
var cellIndex = $(this).index(); |
|
374
|
|
|
var timeId = parseInt($(this).attr('id')); |
|
375
|
|
|
var table = document.getElementById('selected-dates-table'); |
|
376
|
|
|
var rows = table.rows; |
|
377
|
|
|
rows[0].deleteCell(cellIndex); |
|
378
|
|
|
for (var i=1; i<rows.length; i++) { |
|
379
|
|
|
var row = rows[i]; |
|
380
|
|
|
var delIndex = g_chosen_datetimes.indexOf(parseInt(row.id) + timeId); |
|
381
|
|
|
if (delIndex > -1) { |
|
382
|
|
|
g_chosen_datetimes.splice(delIndex, 1); |
|
383
|
|
|
} |
|
384
|
|
|
row.deleteCell(cellIndex); |
|
385
|
|
|
} |
|
386
|
|
|
}); |
|
387
|
|
|
|
|
388
|
|
|
$(document).on('click', '.text-row', function() { |
|
389
|
|
|
var tr = $(this).parent(); |
|
390
|
|
|
var rowIndex = tr.index(); |
|
391
|
|
|
var name = $(this).html(); |
|
392
|
|
|
var delIndex = g_chosen_texts.indexOf(name); |
|
393
|
|
|
if (delIndex > -1) { |
|
394
|
|
|
g_chosen_texts.splice(delIndex, 1); |
|
395
|
|
|
} |
|
396
|
|
|
var table = document.getElementById('selected-texts-table'); |
|
397
|
|
|
table.deleteRow(rowIndex); |
|
398
|
|
|
}); |
|
399
|
|
|
|
|
400
|
|
|
$(document).on('click', '.icon-close', function() { |
|
401
|
|
|
selectItem($(this)); |
|
402
|
|
|
}); |
|
403
|
|
|
|
|
404
|
|
|
$(document).on('click', '.icon-checkmark', function() { |
|
405
|
|
|
deselectItem($(this)); |
|
406
|
|
|
}); |
|
407
|
|
|
|
|
408
|
|
|
$(document).on('click', '#text-submit', function() { |
|
409
|
|
|
var text = document.getElementById('text-title'); |
|
410
|
|
|
if (text.value.length === 0) { |
|
411
|
|
|
alert('Please enter a text!'); |
|
412
|
|
|
return false; |
|
413
|
|
|
} |
|
414
|
|
|
insertText(text.value); |
|
415
|
|
|
text.value = ''; |
|
|
|
|
|
|
416
|
|
|
}); |
|
417
|
|
|
|
|
418
|
|
|
$(document).on('click', '.cl_item', function() { |
|
419
|
|
|
var index; |
|
420
|
|
|
var list = document.getElementById('selected-search-list-id'); |
|
421
|
|
|
var isGroup = $(this).hasClass('is-group'); |
|
422
|
|
|
if ($(this).hasClass('selected')) { |
|
423
|
|
|
if (isGroup) { |
|
424
|
|
|
index = g_chosen_groups.indexOf(this.id); |
|
425
|
|
|
} |
|
426
|
|
|
else { |
|
427
|
|
|
index = g_chosen_users.indexOf(this.id); |
|
428
|
|
|
} |
|
429
|
|
|
if (index > -1) { |
|
430
|
|
|
if (isGroup) { |
|
431
|
|
|
g_chosen_groups.splice(index, 1); |
|
432
|
|
|
} |
|
433
|
|
|
else { |
|
434
|
|
|
g_chosen_users.splice(index, 1); |
|
435
|
|
|
} |
|
436
|
|
|
$(this).remove(); |
|
437
|
|
|
} |
|
438
|
|
|
} else { |
|
439
|
|
|
if (!isGroup) { |
|
440
|
|
|
var text = this.id.replace('user_', ''); |
|
441
|
|
|
g_chosen_users.push(this.id); |
|
442
|
|
|
} else { |
|
443
|
|
|
g_chosen_groups.push(this.id); |
|
444
|
|
|
} |
|
445
|
|
|
document.getElementById('user-group-search-box').value = ''; |
|
446
|
|
|
var li = document.createElement('li'); |
|
447
|
|
|
li.id = this.id; |
|
448
|
|
|
li.className = 'cl_item cl_access_item selected' + (isGroup ? ' is-group' : ''); |
|
449
|
|
|
if (!isGroup) { |
|
450
|
|
|
$.post(OC.generateUrl('/apps/polls/get/displayname'), {username: text}, function(data) { |
|
|
|
|
|
|
451
|
|
|
li.appendChild(document.createTextNode(text + " (" + data + ")")); |
|
|
|
|
|
|
452
|
|
|
list.appendChild(li); |
|
453
|
|
|
}); |
|
454
|
|
|
} else { |
|
455
|
|
|
li.appendChild(document.createTextNode($(this).html())); |
|
456
|
|
|
list.appendChild(li); |
|
457
|
|
|
} |
|
458
|
|
|
$(this).remove(); |
|
459
|
|
|
} |
|
460
|
|
|
}); |
|
461
|
|
|
|
|
462
|
|
|
$('.toggleable-row').hover( |
|
463
|
|
|
function() { |
|
464
|
|
|
var td = this.insertCell(-1); |
|
465
|
|
|
td.className = 'toggle-all selected-all'; |
|
466
|
|
|
}, function() { |
|
467
|
|
|
$(this).find('td:last-child').remove(); |
|
468
|
|
|
} |
|
469
|
|
|
); |
|
470
|
|
|
|
|
471
|
|
|
$(document).on('click', '.toggle-all', function() { |
|
472
|
|
|
var children; |
|
473
|
|
|
var i; |
|
474
|
|
|
if ($(this).attr('class').indexOf('selected-all') > -1) { |
|
475
|
|
|
children = $(this).parent().children('.icon-checkmark'); |
|
476
|
|
|
for (i=0; i<children.length; i++) { |
|
477
|
|
|
deselectItem($(children[i])); |
|
478
|
|
|
} |
|
479
|
|
|
$(this).removeClass('selected-all'); |
|
480
|
|
|
$(this).addClass('selected-none'); |
|
481
|
|
|
} else { |
|
482
|
|
|
children = $(this).parent().children('.icon-close'); |
|
483
|
|
|
for (i=0; i<children.length; i++) { |
|
484
|
|
|
selectItem($(children[i])); |
|
485
|
|
|
} |
|
486
|
|
|
$(this).removeClass('selected-none'); |
|
487
|
|
|
$(this).addClass('selected-all'); |
|
488
|
|
|
} |
|
489
|
|
|
}); |
|
490
|
|
|
|
|
491
|
|
|
$('input[type=radio][name=pollType]').change(function() { |
|
492
|
|
|
if (this.value === 'event') { |
|
493
|
|
|
chosen_type = 'event'; |
|
494
|
|
|
document.getElementById('text-select-container').style.display = 'none'; |
|
495
|
|
|
document.getElementById('date-select-container').style.display = 'inline'; |
|
496
|
|
|
} else { |
|
497
|
|
|
chosen_type = 'text'; |
|
498
|
|
|
document.getElementById('text-select-container').style.display = 'inline'; |
|
499
|
|
|
document.getElementById('date-select-container').style.display = 'none'; |
|
500
|
|
|
} |
|
501
|
|
|
}); |
|
502
|
|
|
|
|
503
|
|
|
$('input[type=radio][name=accessType]').click(function() { |
|
504
|
|
|
access_type = this.value; |
|
505
|
|
|
if (access_type === 'select') { |
|
506
|
|
|
$("#access_rights").show(); |
|
507
|
|
|
$("#selected_access").show(); |
|
508
|
|
|
} else { |
|
509
|
|
|
$("#access_rights").hide(); |
|
510
|
|
|
$("#selected_access").hide(); |
|
511
|
|
|
} |
|
512
|
|
|
}); |
|
513
|
|
|
|
|
514
|
|
|
$('input[type=checkbox][name=check_expire]').change(function() { |
|
515
|
|
|
if (!$(this).is(':checked')) { |
|
516
|
|
|
document.getElementById('expireTs').value = ''; |
|
517
|
|
|
} |
|
518
|
|
|
}); |
|
519
|
|
|
|
|
520
|
|
|
$('#user-group-search-box').on('input', debounce(function() { |
|
521
|
|
|
var ul = document.getElementById('live-search-list-id'); |
|
522
|
|
|
while(ul.firstChild) { |
|
523
|
|
|
ul.removeChild(ul.firstChild); |
|
524
|
|
|
} |
|
525
|
|
|
var val = $(this).val(); |
|
526
|
|
|
if (val.length < 3) { |
|
527
|
|
|
return; |
|
528
|
|
|
} |
|
529
|
|
|
var formData = { |
|
530
|
|
|
searchTerm: val, |
|
531
|
|
|
groups: JSON.stringify(g_chosen_groups), |
|
532
|
|
|
users: JSON.stringify(g_chosen_users) |
|
533
|
|
|
}; |
|
534
|
|
|
$.post(OC.generateUrl('/apps/polls/search'), formData, function(data) { |
|
535
|
|
|
for (var i=0; i<data.length; i++) { |
|
536
|
|
|
var ug = data[i]; |
|
537
|
|
|
var li = document.createElement('li'); |
|
538
|
|
|
li.className = 'cl_item cl_access_item'; |
|
539
|
|
|
if (ug.isGroup) { |
|
540
|
|
|
li.id = 'group_' + ug.gid; |
|
541
|
|
|
li.className += ' is-group'; |
|
542
|
|
|
li.appendChild(document.createTextNode(ug.gid + " (group)")); |
|
543
|
|
|
ul.appendChild(li); |
|
544
|
|
|
} else { |
|
545
|
|
|
li.id = 'user_' + ug.uid; |
|
546
|
|
|
li.appendChild(document.createTextNode(ug.uid + " (" + ug.displayName + ")")); |
|
547
|
|
|
var span = document.createElement('span'); |
|
548
|
|
|
span.id = 'sec_name'; |
|
549
|
|
|
span.appendChild(document.createTextNode(ug.uid)); |
|
550
|
|
|
li.appendChild(span); |
|
551
|
|
|
ul.appendChild(li); |
|
552
|
|
|
} |
|
553
|
|
|
} |
|
554
|
|
|
}); |
|
555
|
|
|
}, 250)); |
|
556
|
|
|
|
|
557
|
|
|
$('.live-search-list-user li').each(function(){ |
|
558
|
|
|
$(this).attr('data-search-term', $(this).text().toLowerCase()); |
|
559
|
|
|
}); |
|
560
|
|
|
|
|
561
|
|
|
$('.live-search-box-user').on('keyup', function(){ |
|
562
|
|
|
var searchTerm = $(this).val().toLowerCase(); |
|
563
|
|
|
$('.live-search-list-user li').each(function(){ |
|
564
|
|
|
if ( $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 |
|
565
|
|
|
|| searchTerm.length < 1 |
|
566
|
|
|
) { |
|
567
|
|
|
$(this).show(); |
|
568
|
|
|
} else { |
|
569
|
|
|
$(this).hide(); |
|
570
|
|
|
} |
|
571
|
|
|
}); |
|
572
|
|
|
}); |
|
573
|
|
|
|
|
574
|
|
|
$('.live-search-list-group li').each(function(){ |
|
575
|
|
|
$(this).attr('data-search-term', $(this).text().toLowerCase()); |
|
576
|
|
|
}); |
|
577
|
|
|
|
|
578
|
|
|
$('.live-search-box-group').on('keyup', function(){ |
|
579
|
|
|
var searchTerm = $(this).val().toLowerCase(); |
|
580
|
|
|
$('.live-search-list-group li').each(function(){ |
|
581
|
|
|
if ( $(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 |
|
582
|
|
|
|| searchTerm.length < 1 |
|
583
|
|
|
) { |
|
584
|
|
|
$(this).show(); |
|
585
|
|
|
} else { |
|
586
|
|
|
$(this).hide(); |
|
587
|
|
|
} |
|
588
|
|
|
}); |
|
589
|
|
|
}); |
|
590
|
|
|
|
|
591
|
|
|
var form = document.finish_poll; |
|
592
|
|
|
var submit_finish_poll = document.getElementById('submit_finish_poll'); |
|
593
|
|
|
if (submit_finish_poll !== null) { |
|
594
|
|
|
submit_finish_poll.onclick = function() { |
|
595
|
|
|
if ( g_chosen_datetimes.length === 0 |
|
596
|
|
|
&& g_chosen_texts.length === 0 |
|
597
|
|
|
) { |
|
598
|
|
|
alert(t('polls', 'Nothing selected!\nClick on cells to turn them green.')); |
|
599
|
|
|
return false; |
|
600
|
|
|
} |
|
601
|
|
|
if (chosen_type === 'event') { |
|
602
|
|
|
form.elements.chosenDates.value = JSON.stringify(g_chosen_datetimes); |
|
603
|
|
|
} |
|
604
|
|
|
else { |
|
605
|
|
|
form.elements.chosenDates.value = JSON.stringify(g_chosen_texts); |
|
606
|
|
|
} |
|
607
|
|
|
var title = document.getElementById('pollTitle'); |
|
608
|
|
|
if ( title === null |
|
609
|
|
|
|| title.value.length === 0 |
|
610
|
|
|
) { |
|
611
|
|
|
alert(t('polls', 'You must enter at least a title for the new poll.')); |
|
612
|
|
|
return false; |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
if (access_type === 'select') { |
|
616
|
|
|
if ( g_chosen_groups.length === 0 |
|
617
|
|
|
&& g_chosen_users === 0 |
|
618
|
|
|
) { |
|
619
|
|
|
alert(t('polls', 'Please select at least one user or group!')); |
|
620
|
|
|
return false; |
|
621
|
|
|
} |
|
622
|
|
|
form.elements.accessValues.value = JSON.stringify({ |
|
623
|
|
|
groups: g_chosen_groups, |
|
624
|
|
|
users: g_chosen_users |
|
625
|
|
|
}); |
|
626
|
|
|
} |
|
627
|
|
|
form.elements.isAnonymous.value = isAnonymous; |
|
628
|
|
|
form.elements.hideNames.value = hideNames; |
|
629
|
|
|
form.submit(); |
|
|
|
|
|
|
630
|
|
|
}; |
|
631
|
|
|
} |
|
632
|
|
|
}); |
|
633
|
|
|
|
|
634
|
|
|
|